package com.kalvin.kvf.modules.fn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.fn.entity.Users;
import com.kalvin.kvf.modules.fn.service.UsersService;
import java.util.List;


/**
 * <p>
 * 风能 股东表 前端控制器
 * </p>
 * @since 2021-07-26 10:37:37
 */
@RestController
@RequestMapping("fn/users")
public class UsersController extends BaseController {

    @Autowired
    private UsersService usersService;



    @RequiresPermissions("fn:users:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("fn/users");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("fn/users_edit");
        Users users;
        if (id == null) {
            users = new Users();
        } else {
            users = usersService.getById(id);
        }
        mv.addObject("editInfo", users);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(Users users) {
        Page<Users> page = usersService.listUsersPage(users);
        return R.ok(page);
    }

    @RequiresPermissions("fn:users:add")
    @PostMapping(value = "add")
    public R add(Users users) {
        usersService.save(users);
        return R.ok();
    }

    @RequiresPermissions("fn:users:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List<Long> ids) {
        usersService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("fn:users:edit")
    @PostMapping(value = "edit")
    public R edit(Users users) {
        usersService.updateById(users);
        return R.ok();
    }

    @RequiresPermissions("fn:users:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        usersService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(usersService.getById(id));
    }

}

